<?php

namespace app\controller;

use app\model\Admin;
use think\Controller;
use think\Request;
use think\Session;

class Login extends Controller
{
    /**
     * 显示资源列表
     *
     * @return \think\Response
     */
    public function index()
    {
        return view();
    }

    /**
     * 登录操作
     * @param Request $request
     */
    public function loginaction( Request $request )
    {
        $post = $request->post();

        $model = new admin();

        $re = $model->adminLogin( $post );

        if ( $re[ 'status' ] ) {

            Session::set('isLogin','1');
            Session::set('admin_email',$re['info']['email']);
            Session::set('name',$re['info']['name']);
            $this->success( '登录成功' ,'index/index');

        } else {

            $this->error( $re[ 'info' ] );

        }

    }

    /**
     * 登出操作
     */
    public function logout(  )
    {
        db('log')->insert(['cd'=>time(),'content'=>'管理员：'.Session::get('name').'登出了系统']);
        Session::clear();
        $this->redirect('login/index');
    }

}
